from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver=webdriver.Chrome()
driver.get('https://www.baidu.com')

# 标签+属性
# kw=driver.find_element(By.CSS_SELECTOR,'#kw')
# print(kw.get_attribute('outerHTML'))
# s_ipt=driver.find_element(By.CSS_SELECTOR,'.s_ipt')
# print(s_ipt.get_attribute('outerHTML'))
# input1=driver.find_element(By.CSS_SELECTOR,'input[id="su"]')
# print(input1.get_attribute('outerHTML'))

# 层级
# input2=driver.find_elements(By.CSS_SELECTOR,'form[id="form"] input')#找到form标签下的所有后代input标签
# for i in input2:
#     print(i.get_attribute('outerHTML'))
#
# print('*'*100)
# input3=driver.find_elements(By.CSS_SELECTOR,'form[id="form"]>input')#找到form标签下子代input标签
# for i in input3:
#     print(i.get_attribute('outerHTML'))

#索引
# input4=driver.find_element(By.CSS_SELECTOR,'form[id="form"] :nth-child(8)')#找到form标签下的地8个标签
# print(input4.get_attribute('outerHTML'))
# input5=driver.find_element(By.CSS_SELECTOR,'form[id="form"] input:nth-of-type(3)')#找到所有form标签下的第三个input标签
# print(input5.get_attribute('outerHTML'))

#模糊匹配
input6=driver.find_element(By.CSS_SELECTOR,'input[name*="w"]')
print(input6.get_attribute('outerHTML'))

# 逻辑连接
input7=driver.find_element(By.CSS_SELECTOR,'input[id="kw"][name="wd"]')
print(input7.get_attribute('outerHTML'))












time.sleep(3)
driver.quit()